<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>闪现轮播1</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .wrapper{
            position: relative;
            width: 1200px;
            height: 460px;
            margin: 100px auto;
            border: 1px solid rgba(0, 0, 0, 0.8);
        }
        .wrapper .img{
            width: 100%;
            height: 100%;
        }
        .wrapper .arr{
            position: absolute;
            top: 50%;
            width: 30px;
            height: 72px;
            margin-top: -36px;
            background-color: rgba(0, 0, 0, .3);
            font-size: 20px;
            text-align: center;
            line-height: 72px;
        }
        .wrapper .arr.arr-l{
            left:234px; 
        }
        .wrapper .arr.arr-r{
            right: 0;
        }
        .wrapper .arr:hover{
            background-color: rgba(0, 0, 0, 0.7);
            color: #fff;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <div class="wrapper">
        <img class="img" src="img/m1.jpg" alt="">
        <div class="arr arr-l" onclick="goPrevious()"><</div>
        <div class="arr arr-r" onclick="goNext()">></div>
    </div>

    <script>
        var imgs = ['m1.jpg','m2.jpg','m3.jpg','m4.jpg','m5.jpg'];
        // 设定全局计数器
        var count = 0;
        var imgEl = document.querySelector('.img');
        
        function goPrevious () {
            count--;
            // 第一张图片再往前  到最后一张
            if ( count < 0 ) {
                count = imgs.length - 1;
            }
            imgEl.src = 'img/' + imgs[count];
        }

        function goNext() {
            count++;
            // 最后一张图片往前  回到第一张
            if (count === imgs.length) {
                count = 0;
            }
            imgEl.src = 'img/' + imgs[count];
        }
    </script>
</body>
</html>